package com.baturu.vin.benz.dto;

import lombok.*;
import lombok.experimental.FieldDefaults;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author jiangxinlei
 * @Time 2017/4/25.
 */
@EqualsAndHashCode(callSuper = false)
@Data
@FieldDefaults(level = AccessLevel.PRIVATE)
@Builder(toBuilder = true)
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class BenzSpring implements Serializable {

    String frontSpringStrut;
    String frontSpring;
    String rearSpring;
    String rearSpringSuppl;

    public boolean hasSpringPartNumber(String partNumber) {
        if (partNumber != null && partNumber.trim().length() > 0) {
            if (frontSpring != null && frontSpring.contains(partNumber)) {
                return true;
            }
            if (rearSpring != null && rearSpring.contains(partNumber)) {
                return true;
            }
            return rearSpringSuppl != null && rearSpringSuppl.contains(partNumber);
        }
        return false;
    }

    public String getSpringParts() {
        return Stream.of(frontSpring, rearSpring, rearSpringSuppl).filter(StringUtils::isNotBlank).collect(Collectors.joining(","));
    }
}
